from django.shortcuts import render
from rest_framework.response import Response
from rest_framework.views import APIView
from goods.models import Goods,Carousel,Category
from goods.serializer import CarouselSer,GoodsSer,CateorySer
class CarouselView(APIView):
    def get(self,request):
        query_set = Carousel.objects.all()
        ser = CarouselSer(query_set,many=True)
        return Response({
            "code":200,
            "msg":"轮播图获取ok",
            "carousel":ser.data,
        })
# class GoodsImg(APIView):
#     def get(self,request):
#         query_srt = Carousel.objects.all()
#
#         ser = CarouselSer(query_srt,many=True)
#         return Response({
#             "code":200,
#             "msg":"论插图获取ok",
#             "carousel":ser.data
#         })

class AllGoodsView(APIView):
    def post(self,request):
        params = request.data.get('price')
        c_name = params["categoryName"]
        query_set = Goods.objects.filter(cate__cate_name=c_name)[:7]
        ser = GoodsSer(query_set,many=True)
        return Response(ser.data)

class HotGoodsView(APIView):
    def post(self,request):
        params = request.data.get('params')
        c_names = params["categoryName"]
        # print(c_names)

        query_set = Goods.objects.order_by("-count").filter(cate__cate_name=c_names)[:7]
        ser = GoodsSer(query_set,many=True)
        return Response(ser.data)
